package main

import (
	"ck-go-test/app"
	"ck-go-test/models"
	"flag"
	"gopkg.in/yaml.v2"
	"io/ioutil"
	"log"
)

// Config 配置
type Config struct {
	App   app.Config
	Model models.Config
}

var (
	cfgPath = flag.String("config", "config.yml", "config file path")
)

func main() {
	cfg := Config{}
	if data, err := ioutil.ReadFile(*cfgPath); nil != err {
		panic(err)
	} else {
		if err := yaml.Unmarshal(data, &cfg); nil != err {
			panic(err)
		}
	}
	if err := models.Setup(cfg.Model); nil != err {
		panic(err)
	}
	app.Run(cfg.App)
	log.Println("Server exiting")
}
